package com.example.administrator.testproject.downM3U8;


import com.example.administrator.testproject.download.DownState;
import com.example.administrator.testproject.download.HttpDownService;
import com.example.administrator.testproject.download.bean.BaseModel;
import com.example.administrator.testproject.download.listener.HttpDownOnNextListener;
import com.litesuits.orm.db.annotation.Ignore;
import com.litesuits.orm.db.annotation.Mapping;
import com.litesuits.orm.db.annotation.Table;
import com.litesuits.orm.db.enums.Relation;

import java.util.ArrayList;
import java.util.List;

/**
 * apk下载请求数据基础类
 * Created by shengfh on 2016/10/20.
 */

@Table("LiteM3U8DownInfo")
public class LiteM3U8DownInfo extends BaseModel {

    private String basepath;

    @Mapping(Relation.OneToMany)

    private List<ItemM3U8Ts> tsList = new ArrayList<>();


    /*存储位置*/
    private String savePath;
    /*文件总长度*/
    private long countLength;
    /*下载长度*/
    private long readLength;
    /*下载唯一的HttpService*/
    @Ignore
    private HttpDownService service;
    /*回调监听*/
    @Ignore
    private HttpDownOnNextListener listener;
    /*超时设置*/
    private  int connectonTime=6;
    /*state状态数据库保存*/
    private int stateInte;
    /*url*/
    private String url;
    private String startStr;

    public LiteM3U8DownInfo() {
    }

    public LiteM3U8DownInfo(String url, HttpDownOnNextListener listener) {
        setUrl(url);
        setListener(listener);
    }

    public LiteM3U8DownInfo(String url) {
        setUrl(url);
    }


    public DownState getState() {
        switch (getStateInte()){
            case 0:
                return DownState.START;
            case 1:
                return DownState.DOWN;
            case 2:
                return DownState.PAUSE;
            case 3:
                return DownState.STOP;
            case 4:
                return DownState.ERROR;
            case 5:
            default:
                return DownState.FINISH;
        }
    }

    public String getStartStr() {
        return startStr;
    }

    public void setStartStr(String startStr) {
        this.startStr = startStr;
    }

    public void setState(DownState state) {
        setStateInte(state.getState());
    }
    public void addTs(ItemM3U8Ts ts) {
        this.tsList.add(ts);
    }

    public int getStateInte() {
        return stateInte;
    }

    public void setStateInte(int stateInte) {
        this.stateInte = stateInte;
    }

    public HttpDownOnNextListener getListener() {
        return listener;
    }

    public void setListener(HttpDownOnNextListener listener) {
        this.listener = listener;
    }

    public HttpDownService getService() {
        return service;
    }

    public void setService(HttpDownService service) {
        this.service = service;
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public String getSavePath() {
        return savePath;
    }

    public void setSavePath(String savePath) {
        this.savePath = savePath;
    }


    public long getCountLength() {
        return countLength;
    }

    public void setCountLength(long countLength) {
        this.countLength = countLength;
    }


    public long getReadLength() {
        return readLength;
    }

    public void setReadLength(long readLength) {
        this.readLength = readLength;
    }


    public int getConnectonTime() {
        return this.connectonTime;
    }

    public void setConnectonTime(int connectonTime) {
        this.connectonTime = connectonTime;
    }

    public String getBasepath() {
        return basepath;
    }

    public void setBasepath(String basepath) {
        this.basepath = basepath;
    }

    public List<ItemM3U8Ts> getTsList() {
        return tsList;
    }

    public void setTsList(List<ItemM3U8Ts> tsList) {
        this.tsList = tsList;
    }


}
